package nio;

import java.io.*;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

public class Channel1 {
    public static void main(String[] args) {
        try {
            String infile="D:\\idea\\LearnBase\\src\\main\\java\\nio\\inputhi.txt";
            String outfile="D:\\idea\\LearnBase\\src\\main\\java\\nio\\outputhi.txt";

            FileInputStream fin=new FileInputStream(infile);
            FileOutputStream fout=new FileOutputStream(outfile);
            FileChannel fcin = fin.getChannel();
            FileChannel fcout = fout.getChannel();

            ByteBuffer buffer = ByteBuffer.allocate(1024);

            while (true) {
                buffer.clear();
                int r=fcin.read(buffer);
                if (r == -1) {
                    break;
                }
                buffer.flip();
                fcout.write(buffer);
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
